from rest_framework import serializers

from goods.models import SKU
from orders.models import OrderInfo, OrderGoods
# 商品详情数据
class SkuSerializers(serializers.ModelSerializer):
    class Meta:
        model = SKU
        fields = ('name', 'default_image_url')

# 订单商品数据
class OrderGoodsSerializers(serializers.ModelSerializer):
    sku = SkuSerializers()
    class Meta:
        model = OrderGoods
        fields = ('sku', 'price', 'count')

# 订单表数据
class OrderSerializer(serializers.ModelSerializer):
    user = serializers.StringRelatedField(label='用户名')
    skus = OrderGoodsSerializers(read_only=True, many=True)
    class Meta:
        model=OrderInfo
        exclude=('address', 'update_time')

# 订单表数据
class OrdersSerializer(serializers.ModelSerializer):
    class Meta:
        model=OrderInfo
        fields=('order_id', 'create_time')